let hl = new Vue({
    el: '#hall-list',
    data: {
        halls: []
    },
    created() {
        $.get('http://localhost:8080/cinema/api/HallListServlet.do', function (dto) {
            hl.halls = dto.value;
        });
    },
    methods: {
        del: function (i, id) {
            let formData = {
                hallId: id
            }
            // 删除前 查询该影厅是否存在相关的放映计划
            $.get('http://localhost:8080/cinema/api/SelectShowsByHallIdServlet.do', formData, function (dto) {
                if (dto.value.length != 0) {
                    layer.msg("该影厅正在出售中，无法进行删除操作！", { offset: 't', icon: 4 });
                    return;
                }

                layer.confirm('确定要删除此影厅嘛？', {skin: 'layui-layer-molv',icon:3,title:'提示',
                    btn: ['是的', '取消'] //按钮
                }, function () {

                    $.ajax({
                        url: 'http://localhost:8080/cinema/api/HallDeleteServlet.do',
                        type: 'delete',
                        data: JSON.stringify(formData),     // 把JavaScript对象，转换为JSON字符串
                        success: function (dto) {
                            if (dto.code == 200) {
                                hl.halls.splice(i, 1)
                                layer.msg(dto.value, { icon: 1, time: 2000 });
                            } else {
                                layer.msg(dto.msg, { icon: 5, time: 2000 });
                            }
                        }
                    });

                }, function () {

                });
            });

        },
        update: function (h) {
            let formData = {
                hallId: h.hallId
            }
            // 修改前 查询该影厅是否存在相关的放映计划
            $.get('http://localhost:8080/cinema/api/SelectShowsByHallIdServlet.do', formData, function (dto) {
                if (dto.value.length != 0) {
                    layer.msg("该影厅正在出售中，无法进行修改操作！", { offset: 't', icon: 4 });
                    return;
                }

                //弹出一个loading层
                var ii = layer.load();
                //此处用setTimeout演示ajax的回调
                setTimeout(function () {

                    layer.close(ii);
                    localStorage.setItem("currentUpdateHall", JSON.stringify(h));
                    location.href = "hall_update.html";

                }, 1000);


            });
        }
    
    }
});